<?php
require_once("../../controllers/init.php");
//echo "Filesystem root = ".$FILE_SYSTEM_ROOT."\n<br>";
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");
//echo "logged on - ".(($IS_LOGGED_ON)?"true\n":"false\n");
require_once($FILE_SYSTEM_ROOT."/model/classes/events/SNAPEvent.php");


$userID = "";
if (isset($_POST['UserID']))$userID=$_POST['UserID'];

//echo "Looking for ".$userID."\n";

//print_r ($GLOBALS['USEROBJECTS']);

$password = "Not Found";
foreach ($GLOBALS['USEROBJECTS'] as $user)
{
//	echo "Found ".$user->getLongName()." and ".$user->getEmail()."\n";
	if (($user->getLongName() == $userID) || ($user->getEmail() == $userID))
	{
		$password = $user->getPassword();
		break;
	}
}

if ($password == "Not Found")
	echo "Not found";
elseif ($password == "")
	echo "No password set. Simply enter your username (".$user->getLongName().") in the Username field and leave the password blank.";
else 
{
	$messageHTML = "";
	$messageHTML .= "<h1>Password Reminder Request</h1>\n";
	$messageHTML .= "<p>You have requested a password reminder. The password on SNAP for the user <b>".$user->getLongName();	
	$messageHTML .= "</b> using email address <b>".$user->getEmail();
	$messageHTML .= "</b> is </p><p><b>".$user->getPassword()."</b></p>";
	$messageHTML .= "<p>If you did not request this password reminder, please contact <a href='mailto://michael.stoddart@stnicholascathedral.co.uk'>michael.stoddart@stnicholascathedral.co.uk</a></p>";
	$message = new Message();
	
	
	$message->addRecipient($user->getEmail());
	
	
	$message->setSubject("SNAP - Password Reminder");
	$message->setFrom("St Nicholas Activity Planning<no-reply@stnicholascathedralmusic.co.uk>");
	$message->addStyle("p, td {font-family: sans-serif;vertical-align:top;font-size: 70%;color:#003366;}");
	$message->addStyle("h1{font-family: sans-serif;font-size: 100%;color:#003366;}");
	$message->addStyle("h2{font-family: sans-serif;font-size: 80%;color:#003366;}");
	$message->addStyle("td.EventReportYear{font-family: sans-serif;font-size: 120%;font-weight: 400; color:#003366;}");
	$message->addStyle("td.EventReportMonth{font-family: sans-serif;font-size: 110%;font-weight: 400; color:#003366;}");
	$message->addStyle("td.EventReportDay{font-family: sans-serif;font-size: 80%;font-weight: 400; color:#003366;}");
	$message->addStyle("table.locationsList {color: #332233; font-weight: 100; padding: 0px; margin: 0px;}");
	$message->addStyle("tr.locationsList {color: #332233; font-weight: 100; padding: 0px; margin: 0px;}");
	$message->addStyle("td.locationsList {color: #332233; font-weight: 100; padding: 0px; margin: 0px;}");
	
	$message->setMessageBody($messageHTML);
	$message->send();
		
}



